#SConscript for libc/sys

import glob
import genwrappers

def gen_wrappers_func(target, source, env):
    fout = open(target[0].path, 'w')
    syscall_no = genwrappers.get_syscall_no(source[0].path)
    genwrappers.generate_datalayout(fout)
    genwrappers.generate_structs(source[2].path, fout)
    genwrappers.generate_wrappers(source[1].path, syscall_no, fout)
    fout.close()
    return None

Import("env")
env = env.Clone()
gen_wrappers_action = env.Action(gen_wrappers_func, "Generating system call wrappers")
env.Depends('syscalls.ll.s', 'genwrappers.py')
env.Command('syscalls.ll.s', ['../../../include/sys/syscall.h',
                'syscalls.list', 'structs.list'], gen_wrappers_action)
env.Clean('syscalls.ll.s', 'genwrappers.pyc')

objs = env.StaticObject(Glob('*.c')) 
objs += env.StaticObject('syscalls.ll.s')
Return('objs')

